<template>
  <div class="app-container">

    <el-form :inline="true" :model="formInline" class="demo-form-inline">
      <el-form-item label="类型名称">
        <el-input v-model="formInline.lxmc" placeholder="类型名称"></el-input>
      </el-form-item>
      <el-form-item label="父级编号">
        <el-input v-model="formInline.lxpri" placeholder="父级编号"></el-input>
      </el-form-item>
      <el-form-item label="选用标识"><strong></strong>
        <el-select v-model="formInline.xybz" placeholder="选用标识">
          <el-option label="全部" value=""></el-option>
          <el-option label="启用" value="Y"></el-option>
          <el-option label="禁用" value="N"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="onSubmit">查询</el-button>
      </el-form-item>

      <el-button type="success" icon="el-icon-document-add" style="margin-left: 10px">
        <router-link to="dictLxEdit">添加类型</router-link>
      </el-button>
    </el-form>

    <el-table :data="tableData.filter(data => !search || data.stuname.toLowerCase().includes(search.toLowerCase()))"
      style="width: 100%">

      <el-table-column type="expand">
        <template slot-scope="props">
          <el-form label-position="left" inline class="demo-table-expand">
            <el-form-item label="住址">
              <span>{{ props.row.address }}</span>
            </el-form-item>
            <el-form-item label="生日">
              <span>{{ props.row.bornDate }}</span>
            </el-form-item>
            <el-form-item label="身份证号">
              <span>{{ props.row.idcard }}</span>
            </el-form-item>
            <el-form-item label="QQ">
              <span>{{ props.row.qq }}</span>
            </el-form-item>
            <el-form-item label="年级">
              <span>{{ props.row.grade.gradename }}</span>
            </el-form-item>
            <el-form-item label="班级">
              <span>{{ props.row.classesid }}</span>
            </el-form-item>
            <el-form-item label="是否住校">
              <span>{{ props.row.isliving }}</span>
            </el-form-item>
            <el-form-item label="宿舍号">
              <span>{{ props.row.livingid }}</span>
            </el-form-item>
            <el-form-item label="家庭情况">
              <span>{{ props.row.familyinfo }}</span>
            </el-form-item>
            <el-form-item label="学生来源">
              <span>{{ props.row.stusourceid }}</span>
            </el-form-item>
            <el-form-item label="入学日期">
              <span>{{ props.row.startschooldate }}</span>
            </el-form-item>
            <el-form-item label="学历">
              <span>{{ props.row.educationid }}</span>
            </el-form-item>
            <el-form-item label="录入日期">
              <span>{{ props.row.creadate }}</span>
            </el-form-item>
            <el-form-item label="备注">
              <span>{{ props.row.des }}</span>
            </el-form-item>
          </el-form>
        </template>
      </el-table-column>

      <el-table-column label="姓名" prop="stuname">
      </el-table-column>

      <el-table-column label="性别" prop="sex" :formatter="sexFormat">
      </el-table-column>

      <el-table-column label="年龄" prop="age" sortable>
      </el-table-column>

      <el-table-column label="职责" prop="job.jobName" width="220">
      </el-table-column>

      <el-table-column label="照片">
        <template slot-scope="scope">
          <el-image style="width: 40px; height: 40px" :src="scope.row.picture" :preview-src-list="bigPic" lazy @click="showBigPic(scope.row.picture)"
            alt="点击图片查看大图预览" title="点击图片查看大图预览">
          </el-image>
        </template>
      </el-table-column>

      <el-table-column label="手机号" prop="privatephone">
      </el-table-column>

      <el-table-column label="家人电话" prop="homephone">
      </el-table-column>

      <el-table-column label="状态" prop="state" :formatter="stateFormat">
      </el-table-column>

      <el-table-column align="right" width="300">
        <template slot="header" slot-scope="scope">
          <el-input v-model="search" size="mini" placeholder="输入关键字搜索" />
        </template>
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)" type="warning" :before-close="handleClose"
            icon="el-icon-edit">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="block">
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" @prev-click="prevClick"
        @next-click="nextClick" :current-page="currentPage" :page-sizes="[5, 10, 20, 50]" :page-size="5" layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </div>
    <div class="app-container">
      <el-drawer title="字典类型修改" :visible.sync="drawer" :direction="direction" :before-close="handleClose" size="40%">

        <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="90px" size="small " class="demo-ruleForm">
          <el-form-item label="类型编号" prop="lxid">
            <el-input v-model="ruleForm.lxid" :disabled="true"></el-input>
          </el-form-item>

          <el-form-item label="类型名称" prop="lxmc">
            <el-input v-model="ruleForm.lxmc"></el-input>
          </el-form-item>

          <el-form-item label="父级类型" prop="lxpri">
            <el-input v-model="ruleForm.lxpri" :disabled="true"></el-input>
          </el-form-item>

          <el-form-item label="类型备注" prop="lxbz">
            <el-input type="textarea" v-model="ruleForm.lxbz"></el-input>
          </el-form-item>

          <el-form-item label="选用标志" prop="xybz">
            <el-radio-group v-model="ruleForm.xybz">
              <el-radio label="Y">启用</el-radio>
              <el-radio label="N">禁用</el-radio>
            </el-radio-group>
          </el-form-item>

          <el-form-item>
            <el-button type="primary" @click="submitForm('ruleForm')">确认</el-button>
            <el-button @click="resetForm('ruleForm')">取消</el-button>
          </el-form-item>
        </el-form>

      </el-drawer>

    </div>
  </div>
</template>



<script>
  import animate from 'animate.css'
  import {
    studentList
  } from '@/api/student'

  export default {
    data() {
      return {
        tableData: [],
        currentPage: 1,
        pageNum: 1,
        pageSize: 5,
        total: 0,
        bigPic: [],
        search: '',
        drawer: false,
        direction: 'rtl',
        formInline: {
          lxmc: '',
          lxpri: 0,
          xybz: ''
        },
        ruleForm: {},
        rules: {
          lxmc: [{
              required: true,
              message: '请输入类型名称',
              trigger: 'blur'
            },
            {
              min: 2,
              max: 5,
              message: '长度在2 到 5 个字符',
              trigger: 'blur'
            }
          ],
          xybz: [{
            required: true,
            message: '请选择是否启用',
            trigger: 'change'
          }],
          lxbz: [{
            required: true,
            message: '请填写类型备注',
            trigger: 'blur'
          }]
        }
      }
    },
    methods: {
      getList() {
        this.loading = true;
        studentList(this.pageNum, this.pageSize).then(res => {
          console.info('res==>', res.data.content)
          this.tableData = res.data.content
          this.total = res.totalElements
          this.listLoading = false
        })
      },
      onSubmit() {
        //alert('submit!');
        //alert(this.formInline.lxmc+":"+this.formInline.lxpri+":"+this.formInline.xybz);
        //this.queryDictLxPage(this.formInline.lxmc, this.formInline.lxpri, this.formInline.xybz, this.pageNo, this.pageSize);
      },
      showBigPic(ele) {
        this.bigPic = [ele]
      },
      sexFormat(row, column) {
        return row[column.property] == 0 ? '男' : '女'
      },
      stateFormat(row, column) {
        return row[column.property] == 'Y' ? '在学' : row[column.property] == 'N' ? '暂休' : '退学';
      },
      handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
        this.pageSize = val;
        this.getList();
      },
      handleCurrentChange(val) {
        console.log(`当前页: ${val}`);
        this.pageNum = val;
        this.getList();
      },
      prevClick(val) {
        this.pageNum = val;
        this.getList();
      },
      nextClick(val) {
        this.pageNum = val;
        this.getList();
      },
      /**
       * @param {Object} done
       * 关闭抽屉
       */
      handleClose(done) {
        this.$confirm('确认关闭？')
          .then(_ => {
            done();
          })
          .catch(_ => {});
      },
      handleEdit(index, row) {
        console.log(index, row);
        this.drawer = true;
        /* this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });
        }); */
      },
      handleDisable(index, row) {
        console.log(index, row.id);
        if (row.id == 1) {
          this.$message({
            type: 'success',
            message: '当前用户不可禁用'
          });
          return;
        }
        this.$confirm('此操作将更改用户名称为' + row.username + '的应用状态, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.loading = true;
          updateUserFlagById({
            id: row.id,
            flag: row.flag
          }).then(res => {
            this.listLoading = false;
            if (res.code == 200) {
              this.$message({
                type: 'success',
                message: res.message
              });
              this.getList();
            } else {
              this.$message({
                type: 'error',
                message: res.message
              });
            }
          })
        }).catch(() => {
          this.loading = false;
          this.$message({
            type: 'info',
            message: '已取消操作'
          });
        });
      }
    },
    mounted() {
      this.getList();
    }
  }
</script>

<style scoped="scoped">
  .el-pagination {
    float: right;
    margin: 10px;
  }

  .demo-table-expand {
    font-size: 0;
  }

  .demo-table-expand label {
    width: 90px;
    color: #99a9bf;
  }

  .demo-table-expand .el-form-item {
    margin-right: 0;
    margin-bottom: 0;
    width: 50%;
  }

  .el-form {
    width: 85%;
    margin: 0 auto;
  }
</style>
